package search.config;


import java.util.ArrayList;
import java.util.List;

public class AnalyzerNames {
	/*
	 * should read from config file
	 */
	final public static String ik_smart = "ik_smart";
	final public static float ik_smart_boost = 2.0f;
	final public static String ik_max_word = "ik_max_word";
	final public static float ik_max_word_boost = 2.0f;


	// 细粒度分词，cover smart遗漏的部分，权重很低
	final public static String ik_max_expa = "ik_max_word";
	final public static float ik_max_expa_boost = 0.2f;
	// 同义词
	final public static String ik_smart_syno = "ik_smart_syno";
	final public static float ik_smart_syno_boost = 0.3f;
	// 上位词
	final public static String ik_smart_hyper = "ik_smart_hyper";
	final public static float ik_smart_hyper_boost = 0.1f;
	// 下位词
	final public static String ik_smart_hypo = "ik_smart_hypo";
	final public static float ik_smart_hypo_boost = 0.2f;
	// 近义词
	final public static String ik_smart_simi = "ik_smart_simi";
	final public static float ik_smart_simi_boost = 0.1f;
	// 别名
	final public static String ik_smart_alia = "ik_smart_alia";
	final public static float ik_smart_alia_boost = 1.0f;
	/*
	 * default
	 */
	public static String default_query_analyzer = ik_max_word;
	public static String default_index_analyzer = ik_max_word;






	/*
	 * default old version
	 */
	public static String default_analyzer = "ik_max_word";
	public static Integer default_boosting = 3;
	public static String minimumShouldMatch = "100%";
	
	/*
	 * analyzers
	 */
	public static String[] analyzers =  {"ik_max_word","ik_smart_syno","ik_smart_hyper",
		"ik_smart_hypo","ik_smart_simi"} ;
	public static Integer counter = analyzers.length;
	public static Integer[] boosting = {5, 3, 2 , 2 , 2};
	
	/*
	 * 鉴于分词的效果问题，可能还需要使用系统自带的以每个字为单位的“极细粒度”切分
	 * 例如：文档中有词“高质量”，查询中有词“高清”，也是匹配不上的。可以分别测试一下这两个词的分词效果。
	 * 1）在建索引时，在每个“合成搜索域”中，添加一个索引方式("fields":{}）,分词系统自带中文分词（video.json）smartcn
	 * 2）在查询时，添加一个以系统自带中文分词的子查询(ComplexSearchService_V1.java)
	 */
	public static String[] analyzers_v2 =  {ik_max_expa,ik_smart_syno,ik_smart_hyper,
		ik_smart_hypo,ik_smart_simi };
	public static Integer counter_v2 = analyzers_v2.length;
	public static float[] boosting_v2 = {ik_max_expa_boost,ik_smart_syno_boost,ik_smart_hyper_boost,
			ik_smart_hypo_boost,ik_smart_simi_boost };
	//////////////////////////////////////////


	public static String get_analyzer(String analyzer){
		int i = 0;
		for(i = 0; i < analyzers_v2.length; i++){
			if(analyzer.equals(analyzers_v2[i])) return analyzer;
		}
		return ik_smart;
	}

	/************************************************
	 *
	 * @return
     */
	public static  List<String> getExpansionAnalyzers(){
		String[] stringArray = {ik_max_expa,ik_smart_syno,ik_smart_hyper, ik_smart_hypo,ik_smart_simi,ik_smart_alia };
		List<String> stringList = new ArrayList<>();
		for(String str : stringArray){
			stringList.add(str);
		}
		return stringList;
	}

	public static List<Double> getExpasionBoosting() throws Exception{
		float[] integers = {ik_max_expa_boost,ik_smart_syno_boost,ik_smart_hyper_boost,ik_smart_hypo_boost,
				ik_smart_simi_boost, ik_smart_alia_boost};
		if(integers.length != getExpansionAnalyzers().size()){
			throw new Exception("size of boosts does't equal to size of ananlyzers! check AnalyzerNames.java");
		}
		List<Double> integerList = new ArrayList<>();
		for(float integer : integers){
			integerList.add( new Double(integer) );
		}
		return integerList;
	}


}


